//
//  BaseViewController.swift
//  FlameB
//
//  Created by 连俊 on 2020/7/30.
//  Copyright © 2020 连俊. All rights reserved.
//

import UIKit

class BaseViewController: UIViewController {
    var navigationBar: BaseNavigationBar!
    
    //适配的iphoneX
    @available(iOS 11.0, *)
    override func viewSafeAreaInsetsDidChange() {
        super.viewSafeAreaInsetsDidChange()
        navigationBar.snp.updateConstraints { (make) in
            make.left.right.equalToSuperview()
            make.top.equalTo(0)
            make.height.equalTo(self.view.safeAreaInsets.top+44)
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = UIColor.white
        edgesForExtendedLayout = .top
        extendedLayoutIncludesOpaqueBars = true
        if #available(iOS 11.0, *) {
            UIScrollView.appearance().contentInsetAdjustmentBehavior = .never

        } else {
            automaticallyAdjustsScrollViewInsets = false
        }
        
        //添加自定义导航
        navigationBar = BaseNavigationBar(frame: .zero)
        view.addSubview(navigationBar)
        navigationBar.snp.makeConstraints { (make) in
            make.left.right.equalToSuperview()
            make.height.equalTo(64)
            make.top.equalToSuperview()
        }
        
        //添加统一返回按钮
        if self.navigationController != nil && (self.navigationController?.children.count)! >= 2 {
            navigationBar.leftBarButtonItem = UIBarButtonItem.init(image: UIImage(named: "icon_common_backarrow")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(backButtonClicked(_:)))
        }
        
        // 构造UI
        buildView()
        //添加底纹
        fillShadePicture()
        
        // 自定义导航栏前置
        view.bringSubviewToFront(self.navigationBar)
    }
    
    func buildView() {

    }
    
    ///添加填充底纹
    func fillShadePicture(){
        
    }
    
    //action
    @objc func backButtonClicked(_ sender: UIBarButtonItem) {
        self.navigationController?.popViewController(animated: true)
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
